package com.jiahua.utils.database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import com.jiahua.comm.Const;

public class DatabaseUtil {
	
	static Connection	connection  = null;

	/*****************************
	 *                           *
	 *      JDBC  Connection     *
	 *                           *
	 ****************************/
	public static Connection connect() {
		Connection	connection  = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			return null;
		}

		try {
			connection = DriverManager
					.getConnection(Const.POST_DB_JDBC_URL, Const.POST_DB_USER, Const.POST_DB_PASSWORD);
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
		return connection;
	}

	public static void close() {
		if (connection != null) {
			try {
				connection.close();
				connection = null;
			} catch (SQLException e) {
				connection = null;
				e.printStackTrace();
			}
		}
	}
}
